package practice.demo.queue;

import java.sql.*;

/**
 * @ClassName: Mysql
 * @Description: TODO
 * @author YuanMingjie
 * @date May 27, 2020 10:40:24 PM
 * 
 */
public class Mysql {

	static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
	static final String DB_URL = "jdbc:mysql://localhost:3306/message?useSSL=false&&serverTimezone=GMT%2B8&useSSL=false";

	static final String USER = "root";
	static final String PASS = "root";

	public static void add(String str) {
		Connection conn = null;
		Statement stmt = null;
		try {

			Class.forName(JDBC_DRIVER);


			System.out.println("Loading...");
			conn = DriverManager.getConnection(DB_URL, USER, PASS);


			stmt = conn.createStatement();
			PreparedStatement psql;
			String sql;
			sql = "INSERT file(message) VALUES (?);";

			psql = conn.prepareStatement(sql); 
			psql.setString(1, str);
			psql.executeUpdate(); 
			psql.close();



			stmt.close();
			conn.close();
		} catch (SQLException se) {

			se.printStackTrace();
		} catch (Exception e) {
	
			e.printStackTrace();
		} finally {

			try {
				if (stmt != null)
					stmt.close();
			} catch (SQLException se2) {
			}
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException se) {
				se.printStackTrace();
			}
		}
		System.out.println("Goodbye!");
	}
}